The purpose of this utility is to generate a skeleton of your Windows application. The problem with Windows programming is that, a large amount of code must be written just to display a window. This frustrates novice Windows programmers and skilled professionals alike. Normally, a ‘generic’ skeleton is used, which is modified with a text editor. This is cumbersome and error prone. It is better to generate a customized skeleton using a set of templates with a utility that is designed precisely for this operation.
Triggering the application wizard is very simple: Type its name or answer ‘yes’ when Wedit asks you, when creating a new project.
In the first page of the wizard, you should fill in the following fields:
Name |
Purpose |
Name of the project |
Wedit fills this in when the wizard is called from Wedit. This will be used to derive the name of the window classes and the file names. |
Single window |
This is an application that displays only one main window. |
Multiple window |
This is an application that uses the MDI standard. A standard MDI menu will be generated and the code for resizing the main window will be slightly modified when a status bar is active. |
Dialog based |
This is not implemented in this version. |
Dll |
This is a DLL application. The wizard will generate a LibMain only. No window will be created or other visual controls. |
Status bar at the bottom |
The application (either MDI or SDI) will have a status bar where you can display messages or other information to the user. The wizard will generate code to show in the status bar an explicative text of each menu option as the user moves the mouse among different menu items. |
Toolbar |
The application has a toolbar, which can be floating or fixed to the main application window |
TCPIP |
The wizard will generate code at the entry of the program (after the main window is created) to call the WSAStartup API to setup the network, and will generate a call to WSACleanup before the program exists. If you use this option, it is imperative to add ws2_32.lib to the libraries used by your project, since lcclnk does not include that library by default. |
About dialog box |
The wizard will generate code for a callback for a standard ‘About’ dialog box, will modify the OnCommand function to accept the IDM_ABOUT command, and before generating the code, the wizard will call the resource editor to allow you to edit the aspect of the dialog box. You should design a dialog box that at least has a Close button and/or a button with the IDOK id (1). |
Path for the template directory |
Normally, the wizard will look for its templates in the \lcc\lib\wizard directory. If you want to customize the templates, copy them to another directory and then enter the path here. It is impossible to know in advance all possible needs of the users of lcc-win32. This provides an escape hatch so that you can add functionality that was not foreseen at design time. |
Output directory |
The directory to which the output files will be written. |
WinMain file |
The main C source file for the generated code. It defaults to <ProjectName.c>. |
Resources file |
The resource file. It defaults to <ProjectName.rc>. |
Header file |
The file containing the definitions for the symbols that will be needed in the application. It defaults to <ProjectNamewiz.h>. |
To be able to open a window, a window of a specific class has to be registered with the system. The purpose of the first page of the wizard is to let you define exactly the window class. If this looks too complicated to you, press the continue button and leave the default values. In most cases, the default values are appropriate to your needs.
Input field |
Purpose |
Class name |
The name of the main window class. This can be any name. It will default to <ProjectNameWndClass>. |
Byte align client area |
Aligns the Window's client area on a byte boundary (in the x direction) to enhance performance during drawing operations. This style affects the width of the window and its horizontal placement on the display. |
Global class |
An application global class is a window class registered by a dynamic-link library (DLL) and available to all applications in the system. For example, your DLL can call the RegisterClassEx function to register a window class that defines a custom control as an application global class so that all applications can create instances of the custom control. In Windows, all window classes are process specific. An application can create a global class by creating the window class in a DLL and listing the name of the DLL in the registry under the appropriate keys. When a process starts, the system loads the specified DLL in the context of the newly started process before calling the main function in that process. The DLL must register the class during its initialization procedure and must specify the CS_GLOBALCLASS style. After a class has been registered, any application can use it to create any number of windows belonging to that class. Windows does not automatically destroy a class when the DLL that registered it is unloaded. For this reason, the Windows exit procedure of the DLL should call the UnregisterClass function to remove the class. |
Byte align window area |
Aligns the window on a byte boundary (in the x direction) to enhance performance during operations that involve moving or sizing the window. This style affects the width of the window and its horizontal placement on the display. |
Class DC |
Allocates one device context to be shared by all windows in the class. |
Window DC |
Allocates a unique device context for each window in the class. |
Redraw when resized |
Specifies that the entire window is to be redrawn if a movement or size adjustment changes the width or height of the client area. |
Save bits |
Saves, as a bitmap, the portion of the screen image obscured by a window. Windows uses the saved bitmap to re-create the screen image when the window is removed. Windows displays the bitmap at its original location and does not send WM_PAINT messages to windows obscured by the window if other screen actions have not invalidated the stored image. Use this style for small windows that are displayed briefly and then removed before other screen activity takes place (for example, menus or dialog boxes). This style increases the time required to display the window, because the operating system must first allocate memory to store the bitmap. |
Accept double-clicks |
Instructs Windows to send a double-click message to the window procedure when the user double-clicks the mouse while the cursor is within a window belonging to the class. |
No ‘close’ in system menu |
Disables the Close command on the System menu. |
Callback function. |
The name of the function that will handle the messages sent to the windows of this class. Defaults to <MainWndProc>. |
Extra bytes for the class |
Number of bytes to allocate in the class structure to store class specific user data. |
Extra bytes for the window |
Number of bytes to allocate in the window structure to store window specific data. |
Icon |
Name of the icon. Using the ‘browse’ button you can enter an icon file name here. |
Cursor |
Cursor to be used with this class. Using the browse button allows you to input a file name here. |
Background color |
Background color of the window. |
You should click on the button you want to have in your toolbar. If you do not choose at least a single button, the toolbar will not be generated.
Input field |
Description |
Floating |
Creates a toolbar detached from the main window. |
Position at the top |
The toolbar is attached to the top of the client area of the main window. |
Position at the bottom |
The toolbar is attached to the bottom of the client area of the main window. This cannot be used with the status bar style. |
Multi line |
The toolbar can have several lines. |
Has ToolTips |
The toolbar will show explicative strings when the mouse passes above any of its buttons. |
Allow customization |
The user can add/delete toolbar buttons from the toolbar. The system provides a standard dialog box for this. |
Large icons |
The bitmaps in the toolbar are large. |
Small icons |
The bitmaps in the toolbar are small. |
Save tool bar position at application exit |
The position of the toolbar will be saved in the applications registry key. |
Add custom button |
This has not yet been implemented. |
The wizard generates a procedure for creating the main application window. If this looks too complicated, do not alter these parameters; simply press the Continue button. In most cases, these default parameters will be what you want.
The documentation for each of the fields is included below.
The window class should be defined in the preceding panel. It is displayed here for information purposes only.
Input field |
Purpose |
Registry key |
Here you should enter the registry key that the application will use for storing application specific data. Currently, the wizard will use and create code to handle this field only if the main window or the toolbar position should be saved. |
Window Title |
Here you should enter the text to be shown in the frame of the window. |
Border |
Determines whether the window should have a border.
It corresponds to the WS_BORDER window style. |
Caption |
Determines whether the window should have a caption. Corresponds to the WS_CAPTION window style. Implies WS_BORDER. |
Child |
Determines whether the window is a child window. Corresponds to the WS_CHILD window style. This style cannot be used with the WS_POPUP window style. |
Clip children |
Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window. It is on by default. Corresponds to the WS_CLIPCHILDREN window style. |
Clip siblings |
Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. If WS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window. Corresponds to the WS_CLIPSIBLINGS window style. |
Disabled |
Determines whether the window should be disabled at startup. Normally you should not use this option, since a disabled window will receive no input. |
Dialog Frame |
Creates a window that has a border of a style typically used with dialog boxes. A window with this style cannot have a title bar. |
H Scroll |
Determines whether the window should have a horizontal scroll bar. It should not be used if you have used the status bar feature, since the scroll bar will overlay the status bar. |
V scroll |
Determines whether the window should have a vertical scroll bar. This option should not be used with a status bar. |
Maximize |
Determines whether the window should have a maximize box. Note that this is not the WS_MAXIMIZE style, but the WS_MAXIMIZEBOX. |
Minimize |
Determines whether the window should have a minimize box. Note that this is not the WS_MINIMIZE style but the WS_MINIMIZEBOX. |
Popup |
Determines whether to create a popup window. Note that this cannot be used with the WS_CHILD style. |
Sizable |
Determines whether the window can be resized. |
Sys menu |
Determines whether the window should have a system menu. |
Visible |
Determines whether the window should be visible at startup. Normally this should be on. |
Static edge |
Determines whether the window should have a static edge. Normally, this style is not used with main windows. Corresponds to the WS_EX_STATICEDGE style. |
Window edge |
Determines whether the window should have an edge around it. |
Client edge |
Determines whether the window should have an edge around its client area. |
Left scrollbar |
Determines whether the vertical scrollbar should be at the left. Normally not used. |
Transparent |
Determines whether the window should let you see the windows underneath it. |
Accept files |
Determines whether the window should handle the WM_ACCEPTFILES message. |
Tool window |
Window with a smaller caption. Normally not used with main windows. |
Topmost |
Determines whether the window should be always visible. |
Save window position in registry |
Determines whether the window position in screen coordinates should be saved in the registry and restored when the application restarts. |
Once the code has been generated, it must then be modified. Following is a short series of technical tips to allow you to start off quickly.
Action |
What to do |
Adding a new menu item |
· Modify the .rc file and add the menu item you want. The item should have a line of text and a numeric identifier. See the other menu items for ideas on how this is done. · This new numeric identifier should be #defined in the global application header file, that is #included in the .rc file. · Modify the MainWndProc_OnCommand function, adding a new case in its switch statement. This new case should be the same numerical identifier you entered in the header file for this menu item. |
Adding a dialog box |
· Design the dialog box with Weditres.
Normally, you will have several dialog boxes in your application. Therefore, it is best to do is to start a
new project and modify the .rc file with an #include statement of the .dlg
files generated by Weditres. Assume that you name your dialog box set
mydialogs. Weditres will generate a mydialogs.dlg file. You should then add
the line #include « mydialogs.dlg » to the .rc file. This will
allow you to add several dialogs later always using the same names. · After
the design of the dialog box is finished, you have to call it up using the
DialogBox windows primitive. · The
DialogBox primitive needs a callback function that will be called up to
handle the events in the dialog box. You have the choice of having Weditres
generate that procedure for you, or writing your own. If you let Weditres do
it; it will generate a file called mydialogs.c containing all procedures for
your dialog boxes. Include this file in the project of Wedit. · Normally,
a dialog box is called after the user has clicked on a menu item. |
Adding code to handle windows events |
· To
handle the messages that Windows sends you, you should go to the MainWndProc
procedure and add cases to handle the messages. For instance, if you are
interested in the keys the user is typing at the keyboard, you can handle the
message WM_CHAR. To do this, add a case WM_CHAR to the big message switch of
the Windows procedure. |
Updating the status bar |
· The status bar can be updated using the function UpdateStatusBar, which is automatically generated by the wizard. Normally, something similar to « UpdateStatusBar(« New text »,0,0) ; » would be written. This means that the first field of the status bar (field zero) will be changed, and that there are no special flags to be given. |
Adding a new window class |
· You should repeat the code in the InitApplication function to add a new window class. You need a new window procedure too, to handle the messages to this new window, after you create it. You can use the skeleton in the MainWndProc procedure as a model. |
Adding an icon |
· Add the statement myicon ICON myiconfile.ico to the .rc file. |